package test;

/**
 * @PROJECT_NAME: 大数据实训
 * @DESCRIPTION:
 * @USER: 韩冰
 * @DATE: 2022/10/8 0008 15:01
 */
public class maopao {
    public static void main(String[] args) {
        //冒泡排序算法
        int[] n = new int[]{1, 5, 8, 2, 3, 9, 4};
        //需进行length-1次冒泡
        for (int i = 0; i < n.length - 1; i++) {
            for (int j = 0; j < n.length - 1 - i; j++) {
                if (n[j] > n[j + 1]) {
                    int temp = n[j];
                    n[j] = n[j + 1];
                    n[j + 1] = temp;
                }
            }
        }
        System.out.println("从小到大排序后的结果是:");
        for (int i = 0; i < n.length; i++)
            System.out.print(n[i] + " ");
    }
}
